//
//  GJFMerchantDetailTelTableViewCell.m
//  Wedding
//
//  Created by 郭静芬 on 2017/1/3.
//  Copyright © 2017年 郭静芬. All rights reserved.
//

#import "GJFMerchantDetailTelTableViewCell.h"


@interface GJFMerchantDetailTelTableViewCell ()
@property (nonatomic, strong) UIView *back;
@property (nonatomic, strong) UIButton *location;
@property (nonatomic, strong) UILabel *slip;
@property (nonatomic, strong) UIButton *tel;
@property (nonatomic, strong) UIButton *order;
@end

@implementation GJFMerchantDetailTelTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setMerchantModel:(GJFMerchantModel *)merchantModel {
    _merchantModel = merchantModel;
    [self.location setTitle:self.merchantModel.address forState:UIControlStateNormal];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.back.frame = CGRectMake(10 * XX, 0, WIDTH - 20 * XX, 70 * YY);
    self.location.frame = CGRectMake(5 * XX, 0, self.back.frame.size.width / 4 * 3 - 10 * XX, 70 * YY);
    self.slip.frame = CGRectMake(self.back.frame.size.width / 4 * 3 + 10 * XX, 20 * YY, 1, 30 * YY);
    self.tel.frame = CGRectMake(self.back.frame.size.width / 4 * 3 + 30 * XX, 10 * YY, 30 * YY, 30 * YY);
    self.order.frame = CGRectMake(self.back.frame.size.width / 4 * 3 + 15 * XX, 40 * YY, 60 * XX, 25 * YY);
}
#pragma mark - 代理人调用点击位置的协议方法
- (void)locationAction {
    if (_delegate && [_delegate respondsToSelector:@selector(clickLocationActionWithLatitude:longitude:)]) {
        [_delegate clickLocationActionWithLatitude:self.merchantModel.latitude longitude:self.merchantModel.longitude];
    }
}
#pragma mark - 代理人调用点击电话的协议方法
- (void)telAction {
    if (_delegate && [_delegate respondsToSelector:@selector(clickTelAction)]) {
        [_delegate clickTelAction];
    }
}

- (UIView *)back {
    if (!_back) {
        _back = [[UIView alloc] init];
        _back.layer.borderColor = HOMECOLOR.CGColor;
        _back.layer.borderWidth = 1;
        _back.layer.cornerRadius = 10 * YY;
        _back.clipsToBounds = YES;
        [self.contentView addSubview:_back];
    }
    return _back;
}
- (UIButton *)location {
    if (!_location) {
        _location = [[UIButton alloc] init];
        _location.titleLabel.numberOfLines = 2;
        [_location setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_location addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
        [self.back addSubview:_location];
    }
    return _location;
}

- (UILabel *)slip {
    if (!_slip) {
        _slip = [[UILabel alloc] init];
        _slip.backgroundColor = [UIColor grayColor];
        [self.back addSubview:_slip];
    }
    return _slip;
}
- (UIButton *)tel {
    if (!_tel) {
        _tel = [[UIButton alloc] init];
        [_tel setImage:[UIImage imageNamed:@"电话"] forState:UIControlStateNormal];
        [_tel addTarget:self action:@selector(telAction) forControlEvents:UIControlEventTouchUpInside];
        [self.back addSubview:_tel];
    }
    return _tel;
}
- (UIButton *)order {
    if (!_order) {
        _order = [[UIButton alloc] init];
        [_order setTitle:@"预约" forState:UIControlStateNormal];
        [_order setTitleColor:HOMECOLOR forState:UIControlStateNormal];
        _order.layer.borderColor = HOMECOLOR.CGColor;
        [_order addTarget:self action:@selector(telAction) forControlEvents:UIControlEventTouchUpInside];
        [self.back addSubview:_order];
    }
    return _order;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
